package me.dwliu.lab.demo.webflux.controller;

import me.dwliu.lab.demo.webflux.exception.BusinessException;
import me.dwliu.lab.demo.webflux.exception.ServiceExceptionEnum;
import me.dwliu.lab.demo.webflux.model.Employee;
import me.dwliu.lab.demo.webflux.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
public class TestController {

    @GetMapping("test")
    public Mono<Employee> test() {
        Employee employee = new Employee();
        employee.setId(1L);
        employee.setName("test");
        employee.setSalary(11111L);

        return Mono.just(employee);
    }


    @GetMapping("test1")
    public Result<Employee> test1() {
        Employee employee = new Employee();
        employee.setId(1L);
        employee.setName("test");
        employee.setSalary(11111L);

        return Result.success(employee);
    }


    @GetMapping("test2")
    public Result<Employee> test2() {
        Employee employee = new Employee();
        employee.setId(1L);
        employee.setName("test");
        employee.setSalary(11111L);
        if (1 == 1) {
            throw new BusinessException(ServiceExceptionEnum.SYS_ERROR);
        }

        return Result.success(employee);
    }

    @GetMapping("test3")
    public Result<Employee> test3() {
        Employee employee = new Employee();
        employee.setId(1L);
        employee.setName("test");
        employee.setSalary(11111L);
        if (1 == 1) {
            throw new NullPointerException("没有粗面鱼丸");
        }

        return Result.success(employee);
    }


}
